package com.wcx.application.controller;

import com.wcx.application.domian.BossBean;
import com.wcx.application.domian.ResumeBean;
import com.wcx.application.service.BossService;
import com.wcx.application.service.ResumeService;
import com.wcx.application.utils.Result;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

@RestController
@RequestMapping("/resume")
@CrossOrigin
public class ResumeController {

    @Autowired
    ResumeService resumeService;


    @GetMapping("/list")
    public Result getList() {
        System.out.println("---" + resumeService.getList());
        return Result.ok().data("list", resumeService.getList());
    }

    @PostMapping("/update")
    public Result update(@RequestBody ResumeBean resumeBean) {
        int i = resumeService.update(resumeBean);
        if (i != 0) {
            return Result.ok();
        } else {
            return Result.error();
        }
    }

    @PostMapping("/search")
    public Result search(@RequestBody ResumeBean resumeBean) {
        System.out.println("---123"+resumeBean.toString());
        return Result.ok().data("list", resumeService.searchList(resumeBean));
    }

    @PostMapping("/create")
    public Result create(@RequestBody ResumeBean resumeBean) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("YYYY年MM月dd日 HH:mm:ss");
        Calendar calendar = Calendar.getInstance();
        String time = simpleDateFormat.format(calendar.getTime());
        resumeBean.setCreateTime(time);
        int i = resumeService.create(resumeBean);
        if (i != 0) {
            return Result.ok();
        } else {
            return Result.error();
        }

    }

    @DeleteMapping("/delete")
    public Result delete(int id) {
        int i = resumeService.delete(id);
        if (i != 0) {
            return Result.ok();
        } else {
            return Result.error();
        }
    }


}